package day4.demo4_乐观锁;

import java.util.concurrent.CountDownLatch;

public class Tst {
    public static void main(String[] args) throws Exception{
        Count c = new Count();
        CountDownLatch cd = new CountDownLatch(2);
        new Thread("add"){
            @Override
            public void run() {
                for (int i = 0; i < 10000; i++) {
                    c.add();
                }
                cd.countDown();
            }
        }.start();

        new Thread("decr"){
            @Override
            public void run() {
                for (int i = 0; i < 10000; i++) {
                    c.dec();
                }
                cd.countDown();
            }
        }.start();

        cd.await();
        System.out.println(c.get());
    }
}
